package com.slkj.shilixiaoyuanapp.ui.user.activity;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.entity.MyclassEntity;
import com.slkj.shilixiaoyuanapp.ui.user.adapter.MyClassAdapter;
import com.slkj.shilixiaoyuanapp.view.MySwipeRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

@ActivityInfo( layout = R.layout.my_class_activity,title = "我的班级")
public class MyClassActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener, MyClassAdapter.onCheckLisener {
    @BindView(R.id.my_class_refresh)
    MySwipeRefreshLayout refreshLayout;
    @BindView(R.id.my_class_recyclerview)
    RecyclerView recyclerView;

    private MyClassAdapter adapter;
    private List<MyclassEntity> list = new ArrayList<>();

    @Override
    protected void init() {
        refreshLayout.setColorSchemeColors(getResources().getColor(R.color.color_green));
        recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        list.add(new MyclassEntity("一年级八班",true));
        list.add(new MyclassEntity("一年级十八班",false));
        adapter = new MyClassAdapter(list,this);
        recyclerView.setAdapter(adapter);
        initListener();
    }
    private void initListener() {
        refreshLayout.setOnRefreshListener(this);
        adapter.setOnCheckLisener(this);
    }

    @Override
    public void onRefresh() {
        list.add(new MyclassEntity("一年级八班",false));
        list.add(new MyclassEntity("一年级十八班",false));
        adapter.notifyDataSetChanged();
        refreshLayout.setRefreshing(false);
    }

    @Override
    public void OnCheckedListener(MyclassEntity chooseAddres, boolean checked) {
        if (checked) {
            for (int i = 0; i < list.size(); i++) {
                list.get(i).setChoose(false);
            }
            chooseAddres.setChoose(checked);
            adapter.notifyDataSetChanged();
        }
    }
}
